{us/bbi/mfdeclre.i} /*DJ01*/
{us/bbi/gplabel.i} /*DJ*/
{us/wb/wbrp01.i}   /*DJ01*/ /* desktop */

DEFINE        VARIABLE m_flag      as   logical        NO-UNDO.
DEFINE        VARIABLE m_ret      as   logical        NO-UNDO.
DEFINE        VARIABLE m_site      as   character        NO-UNDO.



/*One of the Functions used to get field value of frame */
FUNCTION GetTopParent RETURNS HANDLE (INPUT piParentHandle AS HANDLE):

DEFINE VARIABLE poTopParent AS HANDLE NO-UNDO.

IF VALID-HANDLE(piParentHandle) THEN
DO:
  IF piParentHandle:TYPE = "WINDOW" THEN
  DO:
    ASSIGN poTopParent = piParentHandle.
    RETURN poTopParent.
  END.
  ELSE DO:
    ASSIGN piParentHandle = piParentHandle:PARENT.
    poTopParent = GetTopParent (piParentHandle).
    IF VALID-HANDLE(poTopParent) THEN
      RETURN poTopParent.
    ELSE
      RETURN ?.
  END. /* ELSE DO */
END. /* IF VALID-HANDLE */
END FUNCTION.

ON ENDKEY, PF4, F4, end-error  ANYWHERE DO:
   ASSIGN m_flag = NO.
   return.
END. /* ON ENDKEY */
ON GO,RETURN ANYWHERE DO:
/*
   message KEYFUNCTION(LASTKEY) view-as alert-box.
   */
 IF FRAME-NAME = "a" and (KEYFUNCTION(LASTKEY) = "GO" or KEYFUNCTION(LASTKEY) = "RETURN") and
      (frame-field = 'lotserial_qty' or frame-field = 'site' or
       frame-field = 'eff_date' or frame-field = 'dr_acct' ) and m_flag = no then do:
       /* To get value to fields */
      RUN GetFieldValue IN THIS-PROCEDURE
      (INPUT "site", INPUT "a", OUTPUT m_site).

      message m_site view-as alert-box.
       RUN SetFieldValue IN THIS-PROCEDURE
      (INPUT "lotserial_qty", INPUT "a", INPUT "1" , OUTPUT m_ret).
      message m_ret view-as alert-box.

  end.

end. /* ON GO,RETURN ANYWHERE DO: */
  
  
  
{us/bbi/gprun.i ""icunis.p""}
  
  
  
  
  
  
  
  
PROCEDURE GetFrame:
DEFINE INPUT PARAMETER piHandle    AS HANDLE NO-UNDO.
DEFINE INPUT PARAMETER piFrameName AS CHAR   NO-UNDO.
DEFINE OUTPUT PARAMETER poHandle   AS HANDLE NO-UNDO.

DEFINE VARIABLE hChild AS HANDLE NO-UNDO.

IF VALID-HANDLE(piHandle) THEN
DO:
  ASSIGN hChild = piHandle:FIRST-CHILD.
  REPEAT WHILE(VALID-HANDLE(hChild)):
    IF hChild:TYPE = "FRAME" AND hChild:NAME = piFrameName THEN
    DO:
      ASSIGN poHandle = hChild.
      LEAVE.
    END.
    ELSE hChild = hChild:NEXT-SIBLING.
  END.
END.
RETURN "".
END PROCEDURE.


PROCEDURE GetFieldValue:
DEFINE INPUT PARAMETER piFieldName   AS CHAR NO-UNDO.
DEFINE INPUT PARAMETER piFrameName   AS CHAR NO-UNDO.
DEFINE OUTPUT PARAMETER poFieldValue AS CHAR NO-UNDO.

 DEFINE VARIABLE hparent     AS HANDLE     NO-UNDO.
 DEFINE VARIABLE hfldgrp     AS HANDLE     NO-UNDO.
 DEFINE VARIABLE hfield      AS HANDLE     NO-UNDO.


ASSIGN hparent = GetTopParent (SELF).
IF VALID-HANDLE(hparent) THEN
DO:
  RUN GetFrame IN THIS-PROCEDURE
    (INPUT hparent, INPUT piFrameName, OUTPUT hfield).
  IF VALID-HANDLE(hfield) THEN
  DO:
    ASSIGN hfield = hfield:FIRST-CHILD.
    IF hfield:TYPE = "FIELD-GROUP" THEN
    DO:
      ASSIGN hfldgrp = hfield.
      fldgrp:
      REPEAT WHILE(VALID-HANDLE(hfldgrp)):
        ASSIGN hfield = hfldgrp:FIRST-CHILD.
        fld:
        REPEAT WHILE(VALID-HANDLE(hfield)):
                IF hfield:NAME = piFieldName THEN
                DO:
                  ASSIGN poFieldValue = hfield:SCREEN-VALUE.
                  LEAVE fldgrp.
            END.  /* END IF hfield:NAME = "pod_reason" THEN */
            ELSE hfield = hfield:NEXT-SIBLING.
        END. /* END REPEAT WHILE(VALID-HANDLE(hfldgrp)): */
        ASSIGN hfldgrp = hfldgrp:NEXT-SIBLING.
      END.  /* END REPEAT WHILE(VALID-HANDLE(hfldgrp)):*/
    END.  /* END IF hfield:TYPE = "FIELD-GROUP" THEN */
    ELSE
    DO:
      REPEAT WHILE(VALID-HANDLE(hfield)):
        IF hfield:NAME = piFieldName THEN
        DO:
          ASSIGN poFieldValue = hfield:SCREEN-VALUE.
          LEAVE.
        END.   /* END IF hfield:NAME = "pod_reason" THEN */
        ELSE hfield = hfield:NEXT-SIBLING.
      END.  /* END REPEAT WHILE(VALID-HANDLE(hfield)): */
    END.   /* END ELSE IF hfield:TYPE = "FIELD-GROUP" THEN */
  END.  /* END IF VALID-HANDLE(hfield) THEN */
  ELSE RETURN "Not a valid frame".
END.  /* END IF VALID-HANDLE(hparent) THEN  */
ELSE RETURN "Not a valid handle".
RETURN "".
END PROCEDURE.

PROCEDURE SetFieldValue:
DEFINE INPUT PARAMETER piFieldName    AS CHAR NO-UNDO.
DEFINE INPUT PARAMETER piFrameName    AS CHAR NO-UNDO.
DEFINE INPUT PARAMETER piFieldValue   AS CHAR NO-UNDO.
DEFINE OUTPUT PARAMETER poResult      AS LOG  NO-UNDO.

DEFINE VARIABLE hparent     AS HANDLE     NO-UNDO.
DEFINE VARIABLE hfldgrp     AS HANDLE     NO-UNDO.
DEFINE VARIABLE hfield      AS HANDLE     NO-UNDO.

ASSIGN hparent  = GetTopParent (SELF)
       poResult = NO.
IF VALID-HANDLE(hparent) THEN
DO:
  RUN GetFrame IN THIS-PROCEDURE
    (INPUT hparent, INPUT piFrameName, OUTPUT hfield).

  IF VALID-HANDLE(hfield) THEN
  DO:
    ASSIGN hfield = hfield:FIRST-CHILD.
    IF hfield:TYPE = "FIELD-GROUP" THEN
    DO:
      ASSIGN hfldgrp = hfield.
      fldgrp:
      REPEAT WHILE(VALID-HANDLE(hfldgrp)):
        ASSIGN hfield = hfldgrp:FIRST-CHILD.
        fld:
        REPEAT WHILE(VALID-HANDLE(hfield)):
                IF hfield:NAME = piFieldName THEN
                DO:
                  ASSIGN hfield:SCREEN-VALUE = piFieldValue
                         hfield:READ-ONLY = True 
                         hfield:MODIFIED =false
                         poResult = YES.
                  LEAVE fldgrp.
            END.  /* END IF hfield:NAME = "pod_reason" THEN */
            ELSE hfield = hfield:NEXT-SIBLING.
        END. /* END REPEAT WHILE(VALID-HANDLE(hfldgrp)): */
        ASSIGN hfldgrp = hfldgrp:NEXT-SIBLING.
      END.  /* END REPEAT WHILE(VALID-HANDLE(hfldgrp)):*/
    END.  /* END IF hfield:TYPE = "FIELD-GROUP" THEN */
    ELSE
    DO:
      REPEAT WHILE(VALID-HANDLE(hfield)):
        IF hfield:NAME = piFieldName THEN
        DO:
          ASSIGN hfield:SCREEN-VALUE = piFieldValue
          hfield:READ-ONLY = True 
           hfield:MODIFIED =false
                 poResult = YES.
          LEAVE.
        END.   /* END IF hfield:NAME = "pod_reason" THEN */
        ELSE hfield = hfield:NEXT-SIBLING.
      END.  /* END REPEAT WHILE(VALID-HANDLE(hfield)): */
    END.   /* END ELSE IF hfield:TYPE = "FIELD-GROUP" THEN */
  END.  /* END IF VALID-HANDLE(hfield) THEN */
  ELSE RETURN "Not a valid frame".
END.  /* END IF VALID-HANDLE(hparent) THEN  */
ELSE RETURN "Not a valid handle".
RETURN "".
END PROCEDURE.
